package xiaohong.data.tree.binary;

public class BinaryTree {

    TreeNode root;

    //设置根节点
    public void setRoot(TreeNode root) {
        this.root = root;
    }

    //获取根节点
    public TreeNode getRoot() {
        return root;
    }

    //先序遍历
    public void frontShow() {
        if (root != null) {
            root.frontShow();
        }
    }

    // 中序遍历
    public void middleShow() {
        if (root != null) {
            root.middleShow();
        }
    }

    //后序遍历
    public void afterShow() {
        if (root != null) {
            root.afterShow();
        }
    }

    //先序查找
    public TreeNode frontSearch(int i) {
        if (root != null) {
            return root.frontSearch(i);
        }
        return null;
    }

    //先序查找
    public TreeNode middleSearch(int i) {
        if (root != null) {
            return root.middleSearch(i);
        }
        return null;
    }

    //先序查找
    public TreeNode afterSearch(int i) {
        if (root != null) {
            return root.afterSearch(i);
        }
        return null;
    }
    //删除一个子树
    public void delete(int i) {
        if (root.value == i) {
            root = null;
        } else {
            root.delete(i);
        }
    }

}
